package resource;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * @Author quan
 * @Description 将Service类注入到UseController类
 * @Date 2023/7/14 15:23
 */

/**
 * 可以将@Autowired更改为@Resource，也可以执行成功
 */
//@Controller
//public class UserController {
//    @Resource
//    private User user1;
//    public void sayHi(){
//        System.out.println(user1.getName());
//        System.out.println("hello");
//    }
//}

/**
 * 区别：@Autowired找user1没有找到会报错，@Resource虽然也会报错但是有解决办法
 */
@Controller
public class UserController {
//    @Resource(name = "user1")//解决办法：成功
//    @Autowired(name = "user1")//直接标红
    @Autowired
    @Qualifier(value = "user1")
    private User user;
    public void sayHi(){
        System.out.println(user.getName());
        System.out.println("hello");
    }
}
